﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebUI.Utils;
using System.Web.Mvc;

namespace WebUI.Models
{
    public class JsonResultModel
    {
        private JsonResultType _resultType;
        private Boolean _success;
        private string _redirectUrl;
        private string _summaryMessage;
        private List<ErrorMessage> _errors;

        public JsonResultType ResultType { get { return _resultType; } }
        public int Success { get { return _success? 1 : 0; } }
        public string RedirectUrl { get { return _redirectUrl; } }
        public string SummaryMessage { get { return _summaryMessage; } }
        public List<ErrorMessage> Errors { get { return _errors; } }

        public JsonResultModel(JsonResultType resultType, Boolean success, string redirectUrl, string summaryMessage, ModelStateDictionary modelStateDic)
        {
            _resultType = resultType;
            _success = success;
            _redirectUrl = redirectUrl;
            _summaryMessage = summaryMessage;
            _errors = ViewModelUtils.GetAllModelStateErrors(modelStateDic);
        }
    }

    public enum JsonResultType
    {
        Success = 1,
        SuccessWithSummaryMessage = 2,
        SuccessWithRedirectUrl = 3,
        SuccessWithRedirectUrlAndSummaryMessage = 4,

        Error = 11,
        ErrorWithSummaryMessage = 12,
        ErrorWithModelStateErrors = 13,
        ErrorWithSummaryMessageAndModelStateErrors = 14,
        ErrorWithRedirectUrlAndSummaryMessage = 15
    }

    public class ErrorMessage
    {
        public string FieldName { get; set; }
        public string Message { get; set; }
    }
}